package com.gyj;

import java.util.Map;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;

import com.google.common.collect.Maps;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@SpringBootApplication
@EnableFeignClients
@EnableEurekaClient
public class MultiTenancyApplication {

	public static void main(String[] args) {
		SpringApplication.run(MultiTenancyApplication.class, args);
		log.info("=========>服务开启！<=========");
	}

	// 一个是用于在profile微服务运行时动态创建datasource的DataSourceBuilder
	@Bean
	public DataSourceBuilder dataSourceBuilder() {
		DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create().driverClassName("com.mysql.jdbc.Driver");
		return dataSourceBuilder;
	}

	// 一个是用于保存租户id和datasource键值对的CocurrentHashMap，名字是dataSourceMap
	@Bean(name = "dataSourceMap")
	public Map<Object, Object> dataSourceMap() {
		Map<Object, Object> dataSourceMap = Maps.newConcurrentMap();
		return dataSourceMap;
	}

}
